package com.sxygsj.baselibrary.utils

import android.content.Context
import com.qmuiteam.qmui.util.QMUIDisplayHelper

/**
 * Author: sxygsj
 * Date: 2021/3/2 14:43
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
object OtherUtils {
    const val TYPE_DP = 1
    const val TYPE_PX = 2
    const val TYPE_SP = 3

    /**
     * @Description: [dp px sp 互转]
     * @Param: 类型 值
     * @Return: -1 为失败
     */
    fun transition(context: Context, type1: Int, type2: Int, value: Int): Int {
        if (type1 == TYPE_DP && type2 == TYPE_PX) {
            return QMUIDisplayHelper.dp2px(context, value)
        } else if (type1 == TYPE_DP && type2 == TYPE_SP) {
            val px = QMUIDisplayHelper.dp2px(context, value)
            return QMUIDisplayHelper.px2sp(context, px)
        } else if (type1 == TYPE_PX && type2 == TYPE_DP) {
            return QMUIDisplayHelper.px2dp(context, value)
        } else if (type1 == TYPE_PX && type2 == TYPE_SP) {
            return QMUIDisplayHelper.px2sp(context, value)
        } else if (type1 == TYPE_SP && type2 == TYPE_DP) {
            val px=QMUIDisplayHelper.sp2px(context,value)
            return QMUIDisplayHelper.px2dp(context, px)
        } else if (type1 == TYPE_SP && type2 == TYPE_PX) {
            return QMUIDisplayHelper.sp2px(context, value)
        }
        return -1
    }

}